package com.yijinsuo.fragment;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.lzy.okhttputils.model.HttpParams;
import com.nostra13.universalimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;
import com.yijinsuo.R;
import com.yijinsuo.activity.BannerWebViewActivity;
import com.yijinsuo.activity.LoginActivity;
import com.yijinsuo.activity.SeetingsActivity;
import com.yijinsuo.activity.TouZiDetailsActivity;
import com.yijinsuo.adapter.ViewPagerPagerAdapter;
import com.yijinsuo.banner.CycleViewPager;
import com.yijinsuo.banner.ViewFactory;
import com.yijinsuo.base.BaseFragment;
import com.yijinsuo.entity.ADInfo;
import com.yijinsuo.entity.BorrowList;
import com.yijinsuo.http.HttpCallBack;
import com.yijinsuo.http.HttpUtils;
import com.yijinsuo.inteface.OnArticleSelectedListener;
import com.yijinsuo.mian.Config;
import com.yijinsuo.response.BannerRes;
import com.yijinsuo.response.HomeIndexRes;
import com.yijinsuo.tool.SharedPreferencesUtils;
import com.yijinsuo.util.DensityUtil;
import com.yijinsuo.view.CircleProgressViews;
import com.yijinsuo.view.MainTitleBar;
import com.yijinsuo.view.Xcircleindicator;
import com.yijinsuo.view.swipetoloadlayout.base.OnRefreshListener;
import com.yijinsuo.view.swipetoloadlayout.base.SwipeToLoadLayout;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 首页 推荐
 */
public class HomeFragment extends BaseFragment {
    @Bind(R.id.titlebar)
    MainTitleBar titlebar;
    @Bind(R.id.refresh)
    SwipeToLoadLayout mRefresh;
    @Bind(R.id.iv_zou)
    ImageView miv_zou;
    @Bind(R.id.iv_you)
    ImageView miv_you;
    //
    @Bind(R.id.tv_context)
    TextView tv_context;
    @Bind(R.id.viewpager)
    ViewPager mviewpager;
    @Bind(R.id.Xcircleindicator)
    Xcircleindicator mXcircleindicator;
    //
    private ViewPagerPagerAdapter pagerAdapter;
    private List<View> viewList = new ArrayList<View>();   //装载mviewpager滑动的页面
    private ScheduledExecutorService scheduledExecutorService;
    private int currentItem = 0;// 当前页面
    private int preItem = 0;
    //
    private TextView tv_borrowTitle_three, tv_minAmount_three, tv_borrowTimeLimit_three, tv_isDay_three, iv_goumai_three;
    private TextView tv_borrowTitle_two, tv_minAmount_two, tv_borrowTimeLimit_two, tv_isDay_two, iv_goumai_two;
    private TextView tv_borrowTitle_one, tv_minAmount_one, tv_borrowTimeLimit_one, tv_isDay_one, iv_goumai_one;
    private CircleProgressViews circle_progress_three, circle_progress_two, circle_progress_one;
    //
    private TextView tv_more_one, tv_more_two, tv_more_three;

    //viewpager定时滑动
//    private Handler handler = new Handler() {
//
//        @Override
//        public void handleMessage(Message msg) {
//            // 设定viewPager当前页面
//            mviewpager.setCurrentItem(currentItem);
//        }
//    };

    //
    View view;
    //
    private List<ImageView> views = new ArrayList<ImageView>();
    private List<ADInfo> infos = new ArrayList<ADInfo>();
    private CycleViewPager cycleViewPager;
    //
    HomeIndexRes homeres;
    BannerRes bannerres;
    //首页面返回的数据
    private BorrowList borroInfo;
    private BorrowList borroInfotwo;
    private BorrowList borroInfothree;

    //
    private OnArticleSelectedListener mListener;

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
        try {
            mListener = (OnArticleSelectedListener) context;
        } catch (Exception ex) {

            throw new ClassCastException(context.toString() + "must implement OnArticleSelectedListener");
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_home, container, false);
        super.onCreateView(inflater, container, savedInstanceState);
        ButterKnife.bind(this, view);
        return view;
    }

    @Override
    protected void initTitle() {
        titlebar.setTitleBar(0, "亿金所", R.mipmap.login_head);
        //天坑啊 getChildFragmentManager
        cycleViewPager = (CycleViewPager) getChildFragmentManager().findFragmentById(R.id.fragment_cycle_viewpager_content);
        configImageLoader();


        // 用一个定时器 来完成图片切换
//        scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
//        scheduledExecutorService.scheduleAtFixedRate(new ViewPagerTask(), 0, 2000,
//                TimeUnit.MILLISECONDS);


    }
    // 用来完成图片切换的任务
//    private class ViewPagerTask implements Runnable {
//
//        public void run() {
//            // 实现我们的操作
//            // 改变当前页面
//            currentItem = (currentItem + 1) % viewList.size();
//            // Handler来实现图片切换
//            handler.obtainMessage().sendToTarget();
//        }
//    }

    @Override
    protected void initView() {

        //首页面添加3个滑动的view
        View viewone = LayoutInflater.from(getActivity()).inflate(R.layout.viewpaer_item_one, null);
        View viewtwo = LayoutInflater.from(getActivity()).inflate(R.layout.viewpaer_item_two, null);
        View viewthree = LayoutInflater.from(getActivity()).inflate(R.layout.viewpaer_item_three, null);
        //
        tv_borrowTitle_one = (TextView) viewone.findViewById(R.id.tv_borrowTitle_one);
        circle_progress_one = (CircleProgressViews) viewone.findViewById(R.id.circle_progress_one);
        tv_minAmount_one = (TextView) viewone.findViewById(R.id.tv_minAmount_one);
        tv_borrowTimeLimit_one = (TextView) viewone.findViewById(R.id.tv_borrowTimeLimit_one);
        tv_isDay_one = (TextView) viewone.findViewById(R.id.tv_isDay_one);
        iv_goumai_one = (TextView) viewone.findViewById(R.id.iv_goumai_one);
        iv_goumai_one.setOnClickListener(this);
        //
        tv_more_one = (TextView) viewone.findViewById(R.id.tv_more_one);
        //设置下划线
//        tv_more_one.setText(Html.fromHtml("<u>"+"更多"+"</u>"));
        tv_more_one.setOnClickListener(this);

        //
        tv_borrowTitle_two = (TextView) viewtwo.findViewById(R.id.tv_borrowTitle_two);
        circle_progress_two = (CircleProgressViews) viewtwo.findViewById(R.id.circle_progress_two);
        tv_minAmount_two = (TextView) viewtwo.findViewById(R.id.tv_minAmount_two);
        tv_borrowTimeLimit_two = (TextView) viewtwo.findViewById(R.id.tv_borrowTimeLimit_two);
        tv_isDay_two = (TextView) viewtwo.findViewById(R.id.tv_isDay_two);
        iv_goumai_two = (TextView) viewtwo.findViewById(R.id.iv_goumai_two);
        iv_goumai_two.setOnClickListener(this);

        //
        tv_more_two = (TextView) viewtwo.findViewById(R.id.tv_more_two);
        tv_more_two.setOnClickListener(this);
        //
        tv_borrowTitle_three = (TextView) viewthree.findViewById(R.id.tv_borrowTitle_three);
        circle_progress_three = (CircleProgressViews) viewthree.findViewById(R.id.circle_progress_three);
        tv_minAmount_three = (TextView) viewthree.findViewById(R.id.tv_minAmount_three);
        tv_borrowTimeLimit_three = (TextView) viewthree.findViewById(R.id.tv_borrowTimeLimit_three);
        tv_isDay_three = (TextView) viewthree.findViewById(R.id.tv_isDay_three);
        iv_goumai_three = (TextView) viewthree.findViewById(R.id.iv_goumai_three);
        iv_goumai_three.setOnClickListener(this);

        //
        tv_more_three = (TextView) viewthree.findViewById(R.id.tv_more_three);
        tv_more_three.setOnClickListener(this);
        //
        viewList.add(viewone);
        viewList.add(viewtwo);
        viewList.add(viewthree);

        pagerAdapter = new ViewPagerPagerAdapter(viewList);
        mviewpager.setAdapter(pagerAdapter);
//       //设置总共的页数
        mXcircleindicator.initData(viewList.size(), 0);
        //设置当前的页面
        mXcircleindicator.setCurrentPage(0);
        mviewpager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int position) {
                currentItem = position;
                //一定要调用
                mXcircleindicator.setCurrentPage(position);
                //判断viewpager滑动方向
                if (position == preItem) {
//                    Log.i(TAG, "没有移动=====");
                    miv_you.setImageResource(R.mipmap.you);
                    miv_zou.setImageResource(R.mipmap.zou);
                    miv_you.setClickable(true);
                    miv_zou.setClickable(true);
                    return;
                }
                if (position > preItem) {
//                    Log.i(TAG, "从左向右滑=====");
                    //从左向右滑
                    if (position == 1) {
                        miv_you.setImageResource(R.mipmap.you);
                        miv_zou.setImageResource(R.mipmap.zuo_gray);
                        miv_you.setClickable(true);
                        miv_zou.setClickable(true);
                    }
                    if (position == viewList.size() - 1) {
                        miv_you.setImageResource(R.mipmap.you_gray);
                        miv_you.setClickable(false);
                        miv_zou.setImageResource(R.mipmap.zuo_gray);
                        miv_zou.setClickable(true);
                    }

                    return;
                }
                if (position < preItem) {
                    //从右向左滑
//                    Log.i(TAG, "从右向左滑=====");
                    if (position == 1) {
                        miv_you.setImageResource(R.mipmap.you);
                        miv_zou.setImageResource(R.mipmap.zuo_gray);
                        miv_you.setClickable(true);
                        miv_zou.setClickable(true);
                    }
                    if (position == 0) {
                        miv_zou.setImageResource(R.mipmap.zou);
                        miv_zou.setClickable(false);
                        miv_you.setImageResource(R.mipmap.you);
                        miv_you.setClickable(true);
                    }

                    return;
                }


            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

                if (arg2 != 0) {

                }


            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }
        });


        //首页下拉刷新
        mRefresh.setLoadMoreEnabled(false);
        mRefresh.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh() {
//                 //获取首页收据
                views.clear();
                infos.clear();
                getData();
            }
        });
    }


    @Override
    protected void setData() {
        getData();

    }

    private void getData() {
        getBannerData();
        //初始化CircleProgressViews默认设置
//        mCircleProgressView.setRadius(260);
//        mCircleProgressView.setStokewidth(60);
//        mCircleProgressView.setTextSize(60);
//        mCircleProgressView.setColor(getContext().getResources().getColor(R.color.title_line), getContext().getResources().getColor(R.color.dan_hong_6), getContext().getResources().getColor(R.color.black_6));
//        mCircleProgressView.setSpeed(10);
//        mCircleProgressView.setCenterText("年利化利率");
//        mCircleProgressView.setTopText("00.00%");
//        mCircleProgressView.setmTextTopSize(100);
//        mCircleProgressView.setBottomText("利率高 收益稳");
//        mCircleProgressView.setmTextBottmSize(30);

        //初始化CircleProgressViews默认设置
        circle_progress_three.setRadius(DensityUtil.dip2px(getContext(),130));
        circle_progress_three.setStokewidth(DensityUtil.dip2px(getContext(),20));
        circle_progress_three.setTextSize(DensityUtil.sp2px(getContext(),16));
        circle_progress_three.setColor(getContext().getResources().getColor(R.color.title_line), getContext().getResources().getColor(R.color.dan_hong_6), getContext().getResources().getColor(R.color.black_6));
        circle_progress_three.setSpeed(10);
        circle_progress_three.setCenterText("年化收益率");
        circle_progress_three.setTopText("00.00%");
        circle_progress_three.setmTextTopSize(DensityUtil.sp2px(getContext(),35));
        circle_progress_three.setBottomText("利率高 收益稳");
        circle_progress_three.setmTextBottmSize(DensityUtil.sp2px(getContext(),12));

        //初始化CircleProgressViews默认设置
        circle_progress_one.setRadius(DensityUtil.dip2px(getContext(),130));
        circle_progress_one.setStokewidth(DensityUtil.dip2px(getContext(),20));
        circle_progress_one.setTextSize(DensityUtil.sp2px(getContext(),16));
        circle_progress_one.setColor(getContext().getResources().getColor(R.color.title_line), getContext().getResources().getColor(R.color.dan_hong_6), getContext().getResources().getColor(R.color.black_6));
        circle_progress_one.setSpeed(10);
        circle_progress_one.setCenterText("年化收益率");
        circle_progress_one.setTopText("00.00%");
        circle_progress_one.setmTextTopSize(DensityUtil.sp2px(getContext(),35));
        circle_progress_one.setBottomText("利率高 收益稳");
        circle_progress_one.setmTextBottmSize(DensityUtil.sp2px(getContext(),12));

        //初始化CircleProgressViews默认设置
        circle_progress_two.setRadius(DensityUtil.dip2px(getContext(),130));
        circle_progress_two.setStokewidth(DensityUtil.dip2px(getContext(),20));
        circle_progress_two.setTextSize(DensityUtil.sp2px(getContext(),16));
        circle_progress_two.setColor(getContext().getResources().getColor(R.color.title_line), getContext().getResources().getColor(R.color.dan_hong_6), getContext().getResources().getColor(R.color.black_6));
        circle_progress_two.setSpeed(10);
        circle_progress_two.setCenterText("年化收益率");
        circle_progress_two.setTopText("00.00%");
        circle_progress_two.setmTextTopSize(DensityUtil.sp2px(getContext(),35));
        circle_progress_two.setBottomText("利率高 收益稳");
        circle_progress_two.setmTextBottmSize(DensityUtil.sp2px(getContext(),12));

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @OnClick({R.id.titlebar_iv_rignt_img, R.id.iv_you, R.id.iv_zou})
    @Override
    protected void widgetClick(View view) {
        switch (view.getId()) {
//            case R.id.iv_goumai:   //立即投资
//
//                //判断是否登录了  因为在下一个页面统一判断是否登录了
//                Intent intent = new Intent(getActivity(), TouZiDetailsActivity.class);
//                if (null != borroInfo) {
//                    intent.putExtra("borroInfo", borroInfo);
//                    intent.putExtra("type", "1000");
//                    startActivityForResult(intent, 1000);
//                }
//
//                break;


            case R.id.iv_you:    //向右点击切换viewpager

                if (currentItem == viewList.size() - 1) {
                    miv_you.setImageResource(R.mipmap.you_gray);
                    miv_you.setClickable(false);
                } else {

                    currentItem++;
                    mviewpager.setCurrentItem(currentItem);
                }

                break;


            case R.id.iv_zou:   //向右左击切换viewpager
                currentItem--;
                if (currentItem == viewList.size() - 1) {
                    miv_zou.setImageResource(R.mipmap.you_gray);
                } else {

                    mviewpager.setCurrentItem(currentItem);
                }

                break;


            case R.id.iv_goumai_one:

                //判断是否登录了  因为在下一个页面统一判断是否登录了
                Intent intent1 = new Intent(getActivity(), TouZiDetailsActivity.class);
                if (null != borroInfo) {
                    intent1.putExtra("borroInfo", borroInfo);
                    intent1.putExtra("type", "1000");
                    startActivityForResult(intent1, 1000);
                }


                break;


            case R.id.iv_goumai_two:

                //判断是否登录了  因为在下一个页面统一判断是否登录了
                Intent intent2 = new Intent(getActivity(), TouZiDetailsActivity.class);
                if (null != borroInfotwo) {
                    intent2.putExtra("borroInfo", borroInfotwo);
                    intent2.putExtra("type", "1000");
                    startActivityForResult(intent2, 1000);
                }

                break;


            case R.id.iv_goumai_three:

                //判断是否登录了  因为在下一个页面统一判断是否登录了
                Intent intent3 = new Intent(getActivity(), TouZiDetailsActivity.class);
                if (null != borroInfothree) {
                    intent3.putExtra("borroInfo", borroInfothree);
                    intent3.putExtra("type", "1000");
                    startActivityForResult(intent3, 1000);
                }

                break;

            case R.id.titlebar_iv_rignt_img:   //登录
                if (SharedPreferencesUtils.getInstance().isLogin(getActivity(), "userAccount")) {
                    startActivity(new Intent(getActivity(), SeetingsActivity.class));
                } else {

                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }

                break;


            case R.id.tv_more_one:

                mListener.onArticleSelected(1);

                break;


            case R.id.tv_more_two:

                mListener.onArticleSelected(1);

                break;


            case R.id.tv_more_three:

                mListener.onArticleSelected(1);

                break;


            default:
        }
    }

    /**
     * 获取Banner数据
     */
    private void getBannerData() {
        HttpUtils.get(Config.BANNER, new HttpCallBack(getActivity(), "加载中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                if (null != result) {
                    try {
                        bannerres = new BannerRes(new JSONObject(result.toString()));

                        for (int i = 0; i < bannerres.getBannerList().size(); i++) {
                            ADInfo info = new ADInfo();
                            info.setUrl(bannerres.getBannerList().get(i).getBannerUrl());
                            info.setLinkUrl(bannerres.getBannerList().get(i).getLinkUrl());
                            infos.add(info);
                        }

                        //获取首页收据
                        getIndexHomeData();

                        //
                        cycleViewPager.setTv_context(tv_context);
                        // 将最后一个ImageView添加进来
                        views.add(ViewFactory.getImageView(getActivity(), infos.get(infos.size() - 1).getUrl()));
                        for (int i = 0; i < infos.size(); i++) {
                            views.add(ViewFactory.getImageView(getActivity(), infos.get(i).getUrl()));

                        }
                        // 将第一个ImageView添加进来
                        views.add(ViewFactory.getImageView(getActivity(), infos.get(0).getUrl()));
                        //第一次进来的时候显示
                        tv_context.setText(infos.get(0).getUrl());

                        // 设置循环，在调用setData方法前调用
                        cycleViewPager.setCycle(true);

                        // 在加载数据前设置是否循环
                        cycleViewPager.setData(views, infos, mAdCycleViewListener);
                        //设置轮播
                        cycleViewPager.setWheel(true);

                        // 设置轮播时间，默认5000ms
                        cycleViewPager.setTime(2000);
                        //设置圆点指示图标组居中显示，默认靠右
                        cycleViewPager.setIndicatorCenter();


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }


            }


            @Override
            public void onError(String code, String message) {

                Toast.makeText(getActivity(), message, Toast.LENGTH_SHORT).show();
                mRefresh.setRefreshing(false);
            }
        });

    }

    /**
     * 获取首页数据
     */
    private void getIndexHomeData() {
        //
        HttpParams param = new HttpParams();
        HttpUtils.post(Config.HOME_INDEX, param, new HttpCallBack(getActivity(), "加载中...") {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                mRefresh.setRefreshing(false);
                if (null != result) {
                    try {
                        homeres = new HomeIndexRes(new JSONObject(result.toString()));
                        if (homeres.getBorrowList().size() == 1) {
                            borroInfo = homeres.getBorrowList().get(0);
                        }
                        if (homeres.getBorrowList().size() == 2) {
                            borroInfo = homeres.getBorrowList().get(0);
                            borroInfotwo = homeres.getBorrowList().get(1);
                        }
                        if (homeres.getBorrowList().size() == 3) {
                            borroInfo = homeres.getBorrowList().get(0);
                            borroInfotwo = homeres.getBorrowList().get(1);
                            borroInfothree = homeres.getBorrowList().get(2);
                        }
                        //
//                        tvBorrowTitle.setText(borroInfo.getBorrowTitle());
//                        tvMinAmount.setText(borroInfo.getMinAmount());
//                        tvBorrowTimeLimit.setText(borroInfo.getBorrowTimeLimit());
//                        //
////                      mCircleProgressView.setCenterText(borroInfo.getAnnualInterestRate());
//                        mCircleProgressView.setTopText(borroInfo.getAnnualInterestRate() + "%");
//                        int pro = StringValueOfInt(borroInfo.getTenderSum(), borroInfo.getBorrowSum());
//                        mCircleProgressView.setProgress(pro);
//
//                        if (borroInfo.getIsDay().equals("1")) {
//                            tvIsDay.setText("天");
//                        } else {
//                            tvIsDay.setText("个月");
//                        }
//                        circle_progress_one.setCenterText(borroInfo.getAnnualInterestRate());
                        if (null != borroInfo) {

                            tv_borrowTitle_one.setText(borroInfo.getBorrowTitle());
                            tv_minAmount_one.setText(borroInfo.getMinAmount());
                            tv_borrowTimeLimit_one.setText(borroInfo.getBorrowTimeLimit());
                            circle_progress_one.setTopText(borroInfo.getAnnualInterestRate() + "%");
                            circle_progress_one.setProgress(StringValueOfInt(borroInfo.getTenderSum(), borroInfo.getBorrowSum()));
                            circle_progress_one.startProgress();
                        }

                        //
                        if (null != borroInfotwo) {

                            tv_borrowTitle_two.setText(borroInfotwo.getBorrowTitle());
                            tv_minAmount_two.setText(borroInfotwo.getMinAmount());
                            tv_borrowTimeLimit_two.setText(borroInfotwo.getBorrowTimeLimit());
                            circle_progress_two.setTopText(borroInfotwo.getAnnualInterestRate() + "%");
                            circle_progress_two.setProgress(StringValueOfInt(borroInfotwo.getTenderSum(), borroInfotwo.getBorrowSum()));
                            circle_progress_two.startProgress();
                        }

                        //
                        if (null != borroInfothree) {
                            tv_borrowTitle_three.setText(borroInfothree.getBorrowTitle());
                            tv_minAmount_three.setText(borroInfothree.getMinAmount());
                            tv_borrowTimeLimit_three.setText(borroInfothree.getBorrowTimeLimit());
                            circle_progress_three.setTopText(borroInfothree.getAnnualInterestRate() + "%");
                            circle_progress_three.setProgress(StringValueOfInt(borroInfothree.getTenderSum(), borroInfothree.getBorrowSum()));
                            circle_progress_three.startProgress();

                        }

                        //
                        if (null != borroInfo && null != borroInfotwo && null != borroInfothree) {
                            if (borroInfo.getIsDay().equals("1")) {
                                tv_isDay_one.setText("天");
                            } else {
                                tv_isDay_one.setText("个月");
                            }

                            //
                            if (borroInfotwo.getIsDay().equals("1")) {
                                tv_isDay_two.setText("天");
                            } else {
                                tv_isDay_two.setText("个月");
                            }
                            //
                            if (borroInfothree.getIsDay().equals("1")) {
                                tv_isDay_three.setText("天");
                            } else {
                                tv_isDay_three.setText("个月");
                            }

                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                    if (null != borroInfo && null != borroInfotwo && null != borroInfothree) {
                        if (borroInfo.getEndStart().equals("1")) {   //可点击
//                            iv_goumai_one.setClickable(true);
                        } else {
                            iv_goumai_one.setText("筹募期已结束");
//                            iv_goumai_one.setClickable(false);
                        }

                        //
                        if (borroInfotwo.getEndStart().equals("1")) {   //可点击
                            iv_goumai_two.setClickable(true);
                        } else {
                            iv_goumai_two.setText("筹募期已结束");
//                            iv_goumai_two.setClickable(false);
                        }
                        //
                        if (borroInfothree.getEndStart().equals("1")) {   //可点击
                            iv_goumai_three.setClickable(true);
                        } else {
                            iv_goumai_three.setText("筹募期已结束");
//                            iv_goumai_three.setClickable(false);
                        }

                    }

                }

            }

            @Override
            public void onError(String code, String message) {
                mRefresh.setRefreshing(false);
            }
        });

    }


    /**
     * Stirng 转int 化为百分比
     *
     * @param currentnumber
     * @param sum
     * @return
     */

    public int StringValueOfInt(String currentnumber, String sum) {
        float m = Float.valueOf(currentnumber);
        float mm = Float.valueOf(sum);
        return (int) ((m / (int) mm) * 100);
    }

    /**
     * 及时更新homeFragment数据
     */
    public void update() {
        homeres = null;
        getIndexHomeData();
    }

    /**
     * 配置ImageLoder
     */
    private void configImageLoader() {
        // 初始化ImageLoader
        @SuppressWarnings("deprecation")
        DisplayImageOptions options = new DisplayImageOptions.Builder().showStubImage(R.drawable.banner) // 设置图片下载期间显示的图片
                .showImageForEmptyUri(R.drawable.banner) // 设置图片Uri为空或是错误的时候显示的图片
                .showImageOnFail(R.drawable.banner) // 设置图片加载或解码过程中发生错误显示的图片
                .cacheInMemory(true) // 设置下载的图片是否缓存在内存中
                .cacheOnDisc(true) // 设置下载的图片是否缓存在SD卡中
                // .displayer(new RoundedBitmapDisplayer(20)) // 设置成圆角图片
                .build(); // 创建配置过得DisplayImageOption对象

        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getActivity()).defaultDisplayImageOptions(options)
                .threadPriority(Thread.NORM_PRIORITY - 2).denyCacheImageMultipleSizesInMemory()
                .discCacheFileNameGenerator(new Md5FileNameGenerator()).tasksProcessingOrder(QueueProcessingType.LIFO).build();
        ImageLoader.getInstance().init(config);
    }

    private CycleViewPager.ImageCycleViewListener mAdCycleViewListener = new CycleViewPager.ImageCycleViewListener() {

        @Override
        public void onImageClick(ADInfo info, int position, View imageView) {
            if (cycleViewPager.isCycle()) {
                position = position - 1;
//                Toast.makeText(getActivity(), info.getContent(), Toast.LENGTH_SHORT).show();
                if(!info.getLinkUrl().equals("")){
                    Intent intent=new Intent(getActivity(), BannerWebViewActivity.class);
                    intent.putExtra("url",info.getLinkUrl());
                    startActivity(intent);

                }
            }

        }

    };

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode) {
            case 1000:
                getIndexHomeData();
                break;
            default:

        }

    }
}

